CFLAGS = -Wall -fprofile-arcs -ftest-coverage -lm
PROGS = playdom player unittest1 unittest2 unittest3 unittest4 cardtest1 cardtest2 cardtest3 cardtest4 randomtestadventurer randomtestcard

default: all

all: playdom tests

rngs.o: rngs.h rngs.c
	gcc -c rngs.c -g $(CFLAGS)

dominion.o: dominion.h dominion_helpers.h dominion.c rngs.o
	gcc -c dominion.c -g $(CFLAGS)

playdom: dominion.o playdom.c
	gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)

player: player.c interface.o
	gcc -o player player.c -g dominion.o rngs.o interface.o $(CFLAGS)

tests: rngs.o dominion.o unittest1.c unittest2.c unittest3.c unittest4.c cardtest1.c cardtest2.c cardtest3.c cardtest4.c randomtestadventurer.c randomtestcard.c
	gcc -o unittest1 -g unittest1.c dominion.o rngs.o $(CFLAGS)
	gcc -o unittest2 -g unittest2.c dominion.o rngs.o $(CFLAGS)
	gcc -o unittest3 -g unittest3.c dominion.o rngs.o $(CFLAGS)
	gcc -o unittest4 -g unittest4.c dominion.o rngs.o $(CFLAGS)
	gcc -o cardtest1 -g cardtest1.c dominion.o rngs.o $(CFLAGS)
	gcc -o cardtest2 -g cardtest2.c dominion.o rngs.o $(CFLAGS)
	gcc -o cardtest3 -g cardtest3.c dominion.o rngs.o $(CFLAGS)
	gcc -o cardtest4 -g cardtest4.c dominion.o rngs.o $(CFLAGS)
	gcc -o randomtestadventurer -g randomtestadventurer.c dominion.o rngs.o $(CFLAGS)
	gcc -o randomtestcard -g randomtestcard.c dominion.o rngs.o $(CFLAGS)

unittestresults.out: tests
	./unittest1 >> unittestresults.out
	./unittest2 >> unittestresults.out
	./unittest3 >> unittestresults.out
	./unittest4 >> unittestresults.out
	./cardtest1 >> unittestresults.out
	./cardtest2 >> unittestresults.out
	./cardtest3 >> unittestresults.out
	./cardtest4 >> unittestresults.out
	echo "*****Coverage For Unit Test 1*****\n" >> unittestresults.out
	gcov -b unittest1 >> unittestresults.out
	echo "*****Coverage For Unit Test 2*****\n" >> unittestresults.out
	gcov -b unittest2 >> unittestresults.out
	echo "*****Coverage For Unit Test 3*****\n" >> unittestresults.out
	gcov -b unittest3 >> unittestresults.out
	echo "*****Coverage For Unit Test 4*****\n" >> unittestresults.out
	gcov -b unittest4 >> unittestresults.out
	echo "*****Coverage For Card Test 1*****\n" >> unittestresults.out
	gcov -b cardtest1 >> unittestresults.out
	echo "*****Coverage For Card Test 2*****\n" >> unittestresults.out
	gcov -b cardtest2 >> unittestresults.out
	echo "*****Coverage For Card Test 3*****\n" >> unittestresults.out
	gcov -b cardtest3 >> unittestresults.out
	echo "*****Coverage For Card Test 4*****\n" >> unittestresults.out
	gcov -b cardtest4 >> unittestresults.out

randomtestadventurer.out: rngs.o dominion.o randomtestadventurer.c
	./randomtestadventurer >> randomtestadventurer.out
	echo "\n*****Coverage randomtestadventurer*****\n" >> randomtestadventurer.out
	gcov -b randomtestadventurer >> randomtestadventurer.out

randomtestcard.out: rngs.o dominion.o randomtestcard.c
	./randomtestcard >> randomtestcard.out
	echo "\n*****Coverage randomtestcard*****\n" >> randomtestcard.out
	gcov -b randomtestcard >> randomtestcard.out

testDrawCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

badTestDrawCard: badTestDrawCard.c dominion.o rngs.o
	gcc -o badTestDrawCard -g  badTestDrawCard.c dominion.o rngs.o $(CFLAGS)

testBuyCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

testAll: dominion.o testSuite.c
	gcc -o testSuite testSuite.c -g  dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
	gcc -c interface.c -g  $(CFLAGS)

runtests: testDrawCard 
	./testDrawCard >> unittestresult.out
	gcov dominion.c >> unittestresult.out
	cat dominion.c.gcov >> unittestresult.out

clean:
	rm -f *.o $(PROGS) unittestresults.out randomtestadventurer.out randomtestcard.out *.gcov *.gcda *.gcno *.so